package com.yupi.springbootinit.manager;

import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionRequest;
import com.volcengine.ark.runtime.model.completion.chat.ChatMessage;
import com.volcengine.ark.runtime.model.completion.chat.ChatMessageRole;
import com.volcengine.ark.runtime.service.ArkService;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 火山-豆包
 */
@SpringBootTest
public class ChatCompletionsVisionExample {
    @Value("${huoshan.apiKey}")
    String apiKey ;

    @Test
    public void doChat() {

        String baseUrl = "https://ark.cn-beijing.volces.com/api/v3";
        ConnectionPool connectionPool = new ConnectionPool(5, 1, TimeUnit.SECONDS);
        Dispatcher dispatcher = new Dispatcher();
        ArkService service = ArkService.builder().dispatcher(dispatcher).connectionPool(connectionPool).baseUrl(baseUrl).apiKey(apiKey).build();


        System.out.println("----- image input -----");
        final List<ChatMessage> messages = new ArrayList<>();
        final ChatMessage SystemMessage = ChatMessage.builder().role(ChatMessageRole.SYSTEM).content("你是大模型助手，需要回答我的问题？").build();
        final ChatMessage userMessage = ChatMessage.builder().role(ChatMessageRole.USER).content("你是谁").build();

        messages.add(SystemMessage);
        messages.add(userMessage);

        ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
                // 指定您创建的方舟推理接入点 ID，此处已帮您修改为您的推理接入点 ID
                .model("ep-20250325102550-dhjjr")
                .messages(messages)
                .build();

        service.createChatCompletion(chatCompletionRequest).getChoices()
                .forEach(choice -> System.out.println(choice.getMessage().getContent()));

        service.shutdownExecutor();
    }
}